<?php
//+--------------------------------------------
//|描述
//|--------------------------------------------
//|Created by PhpStorm.
//| Author: DRG
//+-------------------------------------------
//|Date: 2018/6/5
//| Time: 11:09
//+--------------------------------------------
namespace app\index\controller;

use app\common\lib\Predis;
use app\common\lib\Redis;
use app\common\lib\Util;

class Login {
    
    public function index() {
        if (empty($_POST['phone_num']) || empty($_POST['code'])) {
            return Util::show(config('empty'), 'phone or code error');
        }
        $r_code = Predis::getInstance()->get(Redis::smsKey($_POST['phone_num']));
//        echo $r_code;
        if ($_POST['code'] == $r_code) {
           //set redis
            $data = [
                'user' => $_POST['phone_num'],
                'srcKey'=>md5(Redis::userKey($_POST['phone_num'])),
                'time'=>time(),
                'isLogin'=>true,
            ];
            //插入成功  提示
            Predis::getInstance()->set(Redis::userKey($_POST['phone_num']), $data);
            
            return Util::show(config('code.success'),'ok', $data);
        } else {
            return Util::show(config('code.error'),'error');
        }
        
    }
    
}